using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;

using PickGold.Charting.Utilities;
using PickGold.Charting.Design;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributeLegendCellColumn_LegendCellColumn"), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class LegendCellColumn : ChartNamedElement, IChartMapArea
	{
		private ContentAlignment _alignment;
		private Color _backColor;
		private LegendCellColumnType _columnType;
		private System.Drawing.Font _font;
		private FontCache _fontCache;
		private Color _foreColor;
		private StringAlignment _headerAlignment;
		private Color _headerBackColor;
		private System.Drawing.Font _headerFont;
		private Color _headerForeColor;
		private string _headerText;
		private string _mapAreaAttribute;
		private Margins _margins;
		private int _maximumCellWidth;
		private int _minimumCellWidth;
		private string _postbackValue;
		private Size _seriesSymbolSize;
		private string _text;
		private string _toolTip;
		private string _url;

		public LegendCellColumn()
			: this(string.Empty, LegendCellColumnType.Text, "#LEGENDTEXT", ContentAlignment.MiddleCenter)
		{
			this._headerFont = this._fontCache.DefaultBoldFont;
		}

		public LegendCellColumn(string headerText, LegendCellColumnType columnType, string text)
			: this(headerText, columnType, text, ContentAlignment.MiddleCenter)
		{
		}

		public LegendCellColumn(string headerText, LegendCellColumnType columnType, string text, ContentAlignment alignment)
		{
			this._text = "#LEGENDTEXT";
			this._foreColor = Color.Empty;
			this._backColor = Color.Empty;
			this._fontCache = new FontCache();
			this._seriesSymbolSize = new Size(200, 70);
			this._alignment = ContentAlignment.MiddleCenter;
			this._toolTip = string.Empty;
			this._margins = new Margins(0, 0, 15, 15);
			this._url = string.Empty;
			this._mapAreaAttribute = string.Empty;
			this._postbackValue = string.Empty;
			this._headerText = string.Empty;
			this._headerAlignment = StringAlignment.Center;
			this._headerForeColor = Color.Black;
			this._headerBackColor = Color.Empty;
			this._minimumCellWidth = -1;
			this._maximumCellWidth = -1;
			this._headerText = headerText;
			this._columnType = columnType;
			this._text = text;
			this._alignment = alignment;
		}

		internal LegendCell CreateNewCell()
		{
			LegendCell cell = new LegendCell();
			cell.CellType = (this.ColumnType == LegendCellColumnType.SeriesSymbol) ? LegendCellType.SeriesSymbol : LegendCellType.Text;
			cell.Text = this.Text;
			cell.ToolTip = this.ToolTip;
			cell.Url = this.Url;
			cell.MapAreaAttributes = this.MapAreaAttributes;
			cell.PostBackValue = this.PostBackValue;
			cell.SeriesSymbolSize = this.SeriesSymbolSize;
			cell.Alignment = this.Alignment;
			cell.Margins = new Margins(this.Margins.Top, this.Margins.Bottom, this.Margins.Left, this.Margins.Right);
			return cell;
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && (this._fontCache != null))
			{
				this._fontCache.Dispose();
				this._fontCache = null;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public bool ShouldSerializeMargins()
		{
			if (((this._margins.Top == 0) && (this._margins.Bottom == 0)) && ((this._margins.Left == 15) && (this._margins.Right == 15)))
			{
				return false;
			}
			return true;
		}

		[SRCategory("CategoryAttributeSeriesItems"), SRDescription("DescriptionAttributeLegendCellColumn_Alignment"), DefaultValue(0x20)]
		public virtual ContentAlignment Alignment
		{
			get
			{
				return this._alignment;
			}
			set
			{
				this._alignment = value;
				this.Invalidate();
			}
		}

		[TypeConverter(typeof(ColorConverter)), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), DefaultValue(typeof(Color), ""), SRDescription("DescriptionAttributeBackColor"), SRCategory("CategoryAttributeSeriesItems")]
		public virtual Color BackColor
		{
			get
			{
				return this._backColor;
			}
			set
			{
				this._backColor = value;
				this.Invalidate();
			}
		}

		[ParenthesizePropertyName(true), SRCategory("CategoryAttributeSeriesItems"), DefaultValue(0), SRDescription("DescriptionAttributeLegendCellColumn_ColumnType")]
		public virtual LegendCellColumnType ColumnType
		{
			get
			{
				return this._columnType;
			}
			set
			{
				this._columnType = value;
				this.Invalidate();
			}
		}

		[DefaultValue((string)null), SRCategory("CategoryAttributeSeriesItems"), SRDescription("DescriptionAttributeLegendCellColumn_Font")]
		public virtual System.Drawing.Font Font
		{
			get
			{
				return this._font;
			}
			set
			{
				this._font = value;
				this.Invalidate();
			}
		}

		[TypeConverter(typeof(ColorConverter)), SRDescription("DescriptionAttributeForeColor"), SRCategory("CategoryAttributeSeriesItems"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), DefaultValue(typeof(Color), "")]
		public virtual Color ForeColor
		{
			get
			{
				return this._foreColor;
			}
			set
			{
				this._foreColor = value;
				this.Invalidate();
			}
		}

		[DefaultValue(typeof(StringAlignment), "Center"), SRDescription("DescriptionAttributeLegendCellColumn_HeaderTextAlignment"), SRCategory("CategoryAttributeHeader")]
		public StringAlignment HeaderAlignment
		{
			get
			{
				return this._headerAlignment;
			}
			set
			{
				if (value != this._headerAlignment)
				{
					this._headerAlignment = value;
					this.Invalidate();
				}
			}
		}

		[SRCategory("CategoryAttributeHeader"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), DefaultValue(typeof(Color), ""), SRDescription("DescriptionAttributeHeaderBackColor"), TypeConverter(typeof(ColorConverter))]
		public virtual Color HeaderBackColor
		{
			get
			{
				return this._headerBackColor;
			}
			set
			{
				this._headerBackColor = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeHeader"), DefaultValue(typeof(System.Drawing.Font), "Microsoft Sans Serif, 8pt, style=Bold"), SRDescription("DescriptionAttributeLegendCellColumn_HeaderFont")]
		public virtual System.Drawing.Font HeaderFont
		{
			get
			{
				return this._headerFont;
			}
			set
			{
				this._headerFont = value;
				this.Invalidate();
			}
		}

		[SRDescription("DescriptionAttributeLegendCellColumn_HeaderColor"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), DefaultValue(typeof(Color), "Black"), SRCategory("CategoryAttributeHeader"), TypeConverter(typeof(ColorConverter))]
		public virtual Color HeaderForeColor
		{
			get
			{
				return this._headerForeColor;
			}
			set
			{
				this._headerForeColor = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeHeader"), DefaultValue(""), SRDescription("DescriptionAttributeLegendCellColumn_HeaderText")]
		public virtual string HeaderText
		{
			get
			{
				return this._headerText;
			}
			set
			{
				this._headerText = value;
				this.Invalidate();
			}
		}

		[SerializationVisibility(SerializationVisibility.Hidden), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual Legend Legend
		{
			get
			{
				if (this.Parent != null)
				{
					return (this.Parent.Parent as Legend);
				}
				return null;
			}
		}

		[SRCategory("CategoryAttributeSeriesItems"), SRDescription("DescriptionAttributeMapAreaAttributes"), Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)), DefaultValue("")]
		public virtual string MapAreaAttributes
		{
			get
			{
				return this._mapAreaAttribute;
			}
			set
			{
				this._mapAreaAttribute = value;
			}
		}

		[NotifyParentProperty(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), SRDescription("DescriptionAttributeLegendCellColumn_Margins"), PersistenceMode(PersistenceMode.InnerProperty), SerializationVisibility(SerializationVisibility.Attribute), SRCategory("CategoryAttributeSeriesItems"), DefaultValue(typeof(Margins), "0,0,15,15")]
		public virtual Margins Margins
		{
			get
			{
				return this._margins;
			}
			set
			{
				this._margins = value;
				this.Invalidate();
			}
		}

		[SRDescription("DescriptionAttributeLegendCellColumn_MaximumWidth"), DefaultValue(-1), SRCategory("CategoryAttributeSize"), TypeConverter(typeof(IntNanValueConverter))]
		public virtual int MaximumWidth
		{
			get
			{
				return this._maximumCellWidth;
			}
			set
			{
				if (value < -1)
				{
					throw new ArgumentException(SR.ExceptionMaximumCellWidthIsWrong, "value");
				}
				this._maximumCellWidth = value;
				this.Invalidate();
			}
		}

		[DefaultValue(-1), TypeConverter(typeof(IntNanValueConverter)), SRDescription("DescriptionAttributeLegendCellColumn_MinimumWidth"), SRCategory("CategoryAttributeSize")]
		public virtual int MinimumWidth
		{
			get
			{
				return this._minimumCellWidth;
			}
			set
			{
				if (value < -1)
				{
					throw new ArgumentException(SR.ExceptionMinimumCellWidthIsWrong, "value");
				}
				this._minimumCellWidth = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeMisc"), SRDescription("DescriptionAttributeLegendCellColumn_Name")]
		public override string Name
		{
			get
			{
				return base.Name;
			}
			set
			{
				base.Name = value;
			}
		}

		[DefaultValue(""), SRCategory("CategoryAttributeSeriesItems"), SRDescription("DescriptionAttributePostBackValue")]
		public string PostBackValue
		{
			get
			{
				return this._postbackValue;
			}
			set
			{
				this._postbackValue = value;
			}
		}

		[SRDescription("DescriptionAttributeLegendCellColumn_SeriesSymbolSize"), DefaultValue(typeof(Size), "200, 70"), SRCategory("CategoryAttributeSeriesItems")]
		public virtual Size SeriesSymbolSize
		{
			get
			{
				return this._seriesSymbolSize;
			}
			set
			{
				if ((value.Width < 0) || (value.Height < 0))
				{
					throw new ArgumentException(SR.ExceptionSeriesSymbolSizeIsNegative, "value");
				}
				this._seriesSymbolSize = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeSeriesItems"), DefaultValue("#LEGENDTEXT"), SRDescription("DescriptionAttributeLegendCellColumn_Text"), Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor))]
		public virtual string Text
		{
			get
			{
				return this._text;
			}
			set
			{
				this._text = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeSeriesItems"), SRDescription("DescriptionAttributeToolTip"), DefaultValue(""), Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor))]
		public virtual string ToolTip
		{
			get
			{
				return this._toolTip;
			}
			set
			{
				this._toolTip = value;
			}
		}

		[SRCategory("CategoryAttributeSeriesItems"), Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)), SRDescription("DescriptionAttributeUrl"), DefaultValue("")]
		public virtual string Url
		{
			get
			{
				return this._url;
			}
			set
			{
				this._url = value;
			}
		}
	}
}

